Lining up the Backtest with Live Trades

We want to lineup our backtest with the original algorithm as closely as possible. It wont be exact in terms of enter/exit prices but the times should line up. This is especially important taking into account the inherent leverage associated with /YM contracts (1 index point equates to $5 per tick), meaning incorrect trading logic error can compound quickly.

Optimization top down

We take an existing profitable algorithm and optimize it to get more robust performance. We take the top down approach in optimization, meaning we start by optimizing the most impactful parameters (ones that alter trading logic more) and funnel down to the parameters with less so. Backtests are run for each parameter individually, then combinations of the best parameters are backtested for the overall algorithm. This is done for two reasons, it decreases the likelihood of over fitting the optimal parameters, and in order to save time as we are dealing with tick data which is extremely granular. Since the original algorithm deals with open candle pricing it requires backtesting on tick data which encapsulates all occured trades. This differs from candle data as candles are constructed over a period of tick data, meaning we go from evaluating 450 data points (9:30AM - 4:00PM EST), to over 450,000 data points per day. This slows down the optimizing process and requires altering the training process.

Why a brute force grid search is not feasible

A grid search requires testing all possible combinations of the parameters which we are optimizing. For us this is First candle (8 values), Take Profit Ratio (9 values), VWAP (5 values), RSI (5 values). This comes out to be 1,800 possible combinations per period of testing (6-months). Since each backtest takes 30-35 minutes to run per period, the brute force grid search method is not preferred, even with having 5 backtests running in parallel. What we do to deal with the granularity of the data is split training into 5 smaller sampling periods, and focus on the parameters (TPR, Candle, VWAP, RSI) individually first. We then find values which have potential. We then take those filtered down top values then implement a much smaller grid search which is more feasible. This is more in line of Bayesian optimization approach.

Training Data

We move onto defining the training periods. There are 5 training periods with each period having a duration of roughly 6-months (2 contracts). Periods were shortened to 6 months in order to deal with the granularity of the data. However, they are crafted in a manner which qualitatively accounts for 1 neutral, 2 bull, and 2 bear market trends as shown below.

Parameters were optimized with training data of roughly 6 months in 2022, 12 months in 2023, and 6 months in 2024, making up about 2 total years.

Testing Data

Testing will take place in 2020, 2021, the second half of 2024, and 2025. Once identified, the optimal strategy will be compared against the original strategy in the testing years stated prior. Those years were chosen in order to avoid over fitting the data as the price history in the testing period were never utilized in identifying our optimal parameters. This would idealy give us robust optimized parameters which work in general rather the specific market conditions used during our training process.

Optimization Parameters

Most to least:
1. First Candle duration
2. Take Profit Ratio
3. Indicator 1 (VWAP)
4. Indicator 2 (RSI)
5. Trailing Stop Losses (Done at the end)

First Candle Duration?

The current strategy initializes an entry long/short based on the high/low of the first 3 minute candle from market open at 9:33 AM EST. We check if the optimal first candle should be [1,2,3,4,5,6,7,10] minutes. Below are the results we came to find across our training periods [1-5] using a take profit ratio of 0.60. The results of returns, sharpe, drawdown, have all been normalized (ranging from 0-1) so that periods can be compared among themselves as periods differ in market conditions. Hovering over we are able to see the individual returns for each period.

GlyphRenderer(
id = '1714', …)
## '/Users/roofernando/Library/CloudStorage/OneDrive-Personal/Trading_job/first_candle_plot.html'

Analyzing the plots above we come to find the first candle values of 2, and 3 minutes coming out with the most consistency. We take note that the lower duration candles 1, 2 minutes outperform during bear market regimes.

Take Profit Ratio

Currently the strategy uses a take profit ratio of 1.0. This means that the exit for profit is the entry point (typically entering at the first candle high or low) plus/minus (long/short) the take profit ratio of 1 multiplied by the difference in the first candle high and first candle low. We look to find the optimal “tpr” from the values of [0.50,0.55,0.60,0.65,0.70,0.75,0.90,1.00,1.20]. Below are the results we came to find across our training periods [1-5] using a first candle of 3 minutes. The results of returns, sharpe, drawdown, have all been normalized (ranging from 0-1) so that periods can be compared amongst themselves.

\[ \text{Exit Long} = C_{High} + tpr * (C_{High} - C_{Low})\] \[ \text{Exit Short} = C_{Low} - tpr * (C_{High} - C_{Low})\]

GlyphRenderer(
id = '3152', …)
## '/Users/roofernando/Library/CloudStorage/OneDrive-Personal/Trading_job/tpr_plot.html'

Evaluating the above graphs we see that a take profit ratio of 0.60 shows the most consistent behavior across all periods measured. We also keep in mind 1.00 going forward as well. We note that 0.6 tpr outperforms during neutral, and bear market periods, while 1.0 does slightly better during bull market periods.

Vwap Indicator

The current strategy does not utilize the VWAP (HLC3, session open) (volume weighted average price) indicator. We look to add a condition such that VWAP should be trending in order for us to enter any trade. Meaning to enter a Long/Short VWAP should be consistently trending up/down as well. How many minutes VWAP should trend in a row (positive for Long or negative for Short) will be the hyper parameter we optimize for. Since this indicator is not in the original strategy we look to find evidence of weather or not to include it going forward. The minutes in a row of VWAP trending we test for are [2,3,4,5]. Below are the results we came to find across our training periods [1-5] using a first candle of 3 minutes and a take profit ratio of 0.60. The results of returns, sharpe, drawdown, have all been normalized (ranging from 0-1) so that periods can be compared among themselves.

GlyphRenderer(
id = '4590', …)
## '/Users/roofernando/Library/CloudStorage/OneDrive-Personal/Trading_job/vwap_plot.html'

We find the VWAP trending values of 2 and 4 to be the most consistent performing. Both perform best during neutral or bull market periods.

RSI (Relative Strength Index: 14 minutes, from session open)

Similar to VWAP above the initial strategy does not utilize RSI indicator. We look to see if adding a condition of trending RSI can improve performance. Meaning to enter a Long/Short RSI should be consistently trending up/down as well. The amount of minutes RSI should be trending in a row (positive for Long or negative for Short) will be the hyper parameter we optimize for. Since this indicator is not in the original algorithm we seek to find evidence of weather or not to include it going forward. The minutes in a row of RSI trending we are testing for are [2,3,4,5]. Below are the results we came to find across our training periods [1-5] using a first candle of 3 minutes and a take profit ratio of 0.60. The results of returns, sharpe, drawdown, have all been normalized (ranging from 0-1) so that periods can be compared among themselves.

GlyphRenderer(
id = '6028', …)
## '/Users/roofernando/Library/CloudStorage/OneDrive-Personal/Trading_job/rsi_plot.html'

There is conclusive results showing a RSI trend of 2 minutes to be consistent across all periods.

Trailing Stop Loss

We look to find a trailing stop loss value which is suitable for minimizing drawdown. Idealy, adding a trailing stop loss we should be able to capture some profit and reduce variance in our trading. Below are the results we came to find across our training periods [1-5] using a first candle of 3 minutes and a take profit ratio of 0.60. The results of returns, sharpe, drawdown, have all been normalized (ranging from 0-1) so that periods can be compared among themselves.

GlyphRenderer(
id = '7466', …)
## '/Users/roofernando/Library/CloudStorage/OneDrive-Personal/Trading_job/tsl_plot.html'

Looking above we see a trailing stop loss of 0.3%-0.5% being good suitors for our strategy. Going forward we go with 0.45% so that give ourselves some room to stay in the trade without getting stopped out too early.

Putting it all together

Returns

Below are the combination results across all 5 periods for strategies with and without trailing stop losses incorporated (0.45%). The dashed blue line is the value to beat as it is the original strategy results. We look for combinations with consistent winners (beating the dashed blue line in returns, sharpe, and drawdown).

Results point to looking at combinations C6, and C24.

GlyphRenderer(
id = '8780', …)
## '/Users/roofernando/Library/CloudStorage/OneDrive-Personal/Trading_job/final_return_plot.html'

Sharpe

GlyphRenderer(
id = '10522', …)
## '/Users/roofernando/Library/CloudStorage/OneDrive-Personal/Trading_job/final_sharpe_plot.html'

Drawdown

GlyphRenderer(
id = '12264', …)
## '/Users/roofernando/Library/CloudStorage/OneDrive-Personal/Trading_job/final_drawdown_plot.html'

Testing Period

Taking into account the way we optimized our models, we note that they were trained during the years 2022 (March-Sept), 2023 (full year), and 2024 (Jan-June). We now test our optimal combinations C6, and C24 out on data which were never used during the optimization process to see if our results are robust in the unseen data. The testing periods we look at are 2020, 2021 full years, 2024 (June-December), and 2025 (Jan-March).

Original Strategy

2020-2022

2024-Present (June-March)

C6 (TPR = 0.6, Candle = 3 minutes, Trailing Stop Loss = 0.0045, Monday Trades = Yes)

2020-2022

2024-Present (June-March)

C24 (TPR = 1.0, Candle = 2 minutes, Trailing Stop Loss = 0.0045, Monday Trades = No)

2020-2022

2024-Present (June-March)

Conclusion

We see that C6 performs well against the original trading strategy. Though it does not exceed returns for the second testing period, it is not too far off and the win rate is consistently around 65% compared to around low 50% of the original. This over a longer period of time ensures C6 is far more robust to the original strategy.